package com.ocm.pay.config.seata;

import com.ocm.core.tool.utils.StringUtil;
import com.zaxxer.hikari.HikariDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class DateSourceConfig {

	@Autowired
	DataSourceProperties dataSourceproperties;

	@Bean
	public DataSource dataSource() {
		HikariDataSource dataSource = dataSourceproperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
		if(StringUtil.hasText(dataSourceproperties.getName())){
			dataSource.setPoolName(dataSourceproperties.getName());
		}
		return new DataSourceProxy(dataSource);

	}

}
